package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 查询排行榜数据: 前10
     * @param category1Id
     * @param type
     * @return
     */
    @GetMapping(value = "/findRankingList/{category1Id}/{type}")
    public Result findRankingList(@PathVariable(value = "category1Id") Long category1Id,
                                  @PathVariable(value = "type") String type){
        return Result.ok(searchService.findRankingList(category1Id, type));
    }

    /**
     * 1106 首页根据一级分类id查询一级分类id下前7热门三级分类下前6热门专辑数据
     * @param category1Id
     * @return
     */
    @GuiguLogin
    @GetMapping("channel/{category1Id}")
    public Result channel(@PathVariable("category1Id") Long category1Id){
        return Result.ok(searchService.channel(category1Id));
    }


    /**
     * 1107 专辑搜索
     * @param albumIndexQuery
     * @return Result
     */
    @GuiguLogin
    @PostMapping
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery){
        return Result.ok(searchService.search(albumIndexQuery));
    }

    /**
     * 1107 提示词功能
     * @param keywords
     * @return Result
     */
    @GuiguLogin
    @GetMapping("/completeSuggest/{keywords}")
    public Result completeSuggest(@PathVariable("keywords") String keywords){
        return Result.ok(searchService.completeSuggest(keywords));
    }

    /**
     * 查询专辑详细页面信息
     * @param albumId
     * @return null
     */
    @GetMapping("/{albumId}")
    public Result getAlbumInfo(@PathVariable("albumId") Long albumId){
        return Result.ok(searchService.getAlbumInfo(albumId));
    }

}

